﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml.Linq;
using System.Xml;
using System.Xml.Serialization;
using System.IO;

namespace WpfApplication1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void SerializeObject(string filename)
        {
            // Writing the file requires a TextWriter.
            TextWriter myStreamWriter = new StreamWriter(filename);

            // Create a Type array.
            Type[] extraTypes = new Type[3];
            extraTypes[0] = typeof(Address);
            extraTypes[1] = typeof(Phone);
            extraTypes[2] = typeof(InternationalPhone);

            // Create the XmlSerializer instance.
            XmlSerializer mySerializer = new XmlSerializer
            (typeof(Teacher), extraTypes);

            Teacher teacher = new Teacher();
            teacher.Name = "Mike";
            // Add extra types to the Teacher object
            object[] info = new object[2];
            info[0] = new Address("Springville");
            info[1] = new Phone("555-0100");

            teacher.Info = info;

            teacher.PhoneInfo = new InternationalPhone("000");

            mySerializer.Serialize(myStreamWriter, teacher);
            myStreamWriter.Close();
        }

        private void Button_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            //矩形对象
            IWBRectangle iwrect1 = new IWBRectangle { X = 1, Y = 1 };
            IWBRectangle iwrect2 = new IWBRectangle { X = 3, Y = 3 };
            //线对象
            IWBLine iwrect3 = new IWBLine { Xx = 4, Yy = 3 };
            IWBLine iwrect4 = new IWBLine { Xx = 5, Yy = 3 };
            //画布页
            IWBPage pg = new IWBPage { ElementList = new List<IWBElementBase> { iwrect1, iwrect3 } };
            IWBPage pg1 = new IWBPage { ElementList = new List<IWBElementBase> { iwrect3, iwrect4 } };
            //最外层viewbox
            IWBSVGViewBox vb = new IWBSVGViewBox();
            vb.AddPage(pg);
            vb.AddPage(pg1);
            //文件对象
            IWBContentXML icon = new IWBContentXML();
            icon.SVGsvg = vb;
            //生成XML
            XmlHelper.XmlSerializeToFile(icon, "test.xml", Encoding.UTF8);
        }

        private void TextBox_KeyDown(object sender, KeyEventArgs e)
        {
            //dynamic file = "C:\\Program Files\\Common Files\\microsoft shared\\ink\\TabTip.exe";
            //if (!System.IO.File.Exists(file))
            //    return;
            //Process.Start(file);
            ////return SetUnDock(); //不知SetUnDock()是什么，所以直接注释返回1
            //return;

            //Process.Start(@"C:\windows\system32\osk.exe");

            //XNamespace ns = "http://www.w3.org/2000/svg";
            //XNamespace ns1 = "http://www.imsglobal.org/xsd/iwb_v1p0";
            //var xDoc = XDocument.Load("XMLFile1.xml");
            //var viewBox = xDoc.Root.Element(ns1+"meta");

            //Type[] personTypes = { typeof(Person), typeof(SpecialPerson), typeof(SuperPerson) };

            //XmlHelper.XmlSerializeToFile(personen, "test.xml", Encoding.UTF8);
            //Console.WriteLine(xml);

            //testModel help = XmlHelper.XmlDeserializeFromFile<testModel>("test.xml", Encoding.UTF8);
            //X1 x1a = new X1 { AA = 1, BB = 2 };
            //X1 x1b = new X1 { AA = 3, BB = 4 };
            //X2 x2 = new X2 { CC = "ccccccccccc", DD = "dddddddddddd" };
            //XRoot root = new XRoot { List = new List<XBase> { x1a, x1b, x2 } };
            //XmlHelper.XmlSerializeToFile(root, "test.xml", Encoding.UTF8);
            //XRoot root= XmlHelper.XmlDeserializeFromFile<XRoot>("test.xml", Encoding.UTF8);
            //SerializeObject("Teacher.xml");
        }
    }
}
